package com.sumainfor.pc.cfo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.cfo.service.InvoiceAuditService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-05-05 18:33
 * 发票开票申请
 */
@RestController
@RequestMapping("/invoice/audit")
public class InvoiceAuditController {

    @Autowired
    private InvoiceAuditService service;

    /**
     * 查询表格的数据
     *
     * @param page
     * @param params InvoType: 发票类型
     *               0:专票
     *               1:普票
     * @return
     */
    @RequestMapping("/getTableList")
    public JsonResult getTableList(Page page, @RequestParam Map<String, Object> params) {
        return service.getTableList(page, params);
    }


    /**
     * 确认开票
     *
     * @param invoiceId
     * @return
     */
    @PostMapping("/affirm")
    public JsonResult affirm(String invoiceId) {
        if (StringUtils.isBlank(invoiceId)) {
            return JsonResult.errorForEmpty();
        }
        return service.affirm(invoiceId);
    }


    /**
     * 驳回开票申请
     *
     * @param invoiceId
     * @return
     */
    @PostMapping("/reject")
    public JsonResult reject(String invoiceId) {
        if (StringUtils.isBlank(invoiceId)) {
            return JsonResult.errorForEmpty();
        }
        return service.reject(invoiceId);
    }


}
